﻿using AdverseEventReportSystem.BLL.NursingFormSystem;
using AdverseEventReportSystem.Utils;
using NursingFormSystem.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AdverseEventReportSystem.Web.Areas.NursingForm.Controllers
{
    [LoginAttribute(IsNeed = false)]
    public class OxytocinController : BaseController
    {
        // GET: NursingForm/Oxytocin
        public ActionResult Index(string patientId, int visitId)
        {
            ViewBag.PatientId = patientId;
            ViewBag.VisitId = visitId;
            return View();
        }

        /// <summary>
        /// 查询列表
        /// </summary>
        /// <returns></returns>
        public ActionResult Search()
        {
            string patientId = WebUtils.GetSafeString("patientId");
            if (patientId.IndexOf('_') > -1)
            {
                patientId = patientId.Split('_')[0];
            }
            int visitId = WebUtils.GetInt("visitId");
            NursingFormSoapClient service = new NursingFormSoapClient();
            ActionOperateResultOfString serviceResult = service.GetNursingFormRecordByDate(patientId, visitId, (int)FormType.Oxytocins, new DateTime(2000, 1, 1), new DateTime(2100, 1, 1));
            List<OXT> list = new List<OXT>();
            if (serviceResult.Code == 1)
            {
                List<NursingFormRecord> recordList = JsonHelper.DeserializeObject<List<NursingFormRecord>>(serviceResult.D);
                foreach (var item in recordList)
                {
                    list.Add(XmlHelper.XmlDeserialize<OXT>(item.NursingFormData));
                }
                list = list.OrderByDescending(r => r.RiQi + "" + r.ShiJian).ToList();
            }
            var result = new { Rows = list };
            return JsonDate(result);
        }
    }
}